﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.JoinParty
{
    public class PartyProbationaryPartyMember 
    {
        #region 属性
        /// <summary>
        /// 预备党员ID
        /// </summary>
        [Key]
        public string MemberID { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [StringLength(128)]
        public string UserName { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        [StringLength(128)]
        public string Gender { get; set; }

        /// <summary>
        /// 工作单位及职务
        /// </summary>
        [StringLength(128)]
        public string UnitsAndPost { get; set; }

        /// <summary>
        /// 党支部通过时间
        /// </summary>
        public DateTime? PassTime { get; set; }

        /// <summary>
        /// 党委审批时间
        /// </summary>
        public DateTime? AppTime { get; set; }

        /// <summary>
        /// 预备期满时间
        /// </summary>
        public DateTime? TimeExpiration { get; set; }

        /// <summary>
        /// 被批准为预备党员时的主要优缺点
        /// </summary>
        [StringLength(128)]
        public string RelativeMerits { get; set; }

        /// <summary>
        /// 所属党组织
        /// </summary>
        [StringLength(128)]
        public string OUID { get; set; }

        /// <summary>
        /// 流程实例ID
        /// </summary>
        [StringLength(128)]
        public string StandID { get; set; }
        #endregion

        #region 查询管理

        /// <summary>
        /// 通过流程ID获取实例ID
        /// </summary>
        /// <param name="StandID"></param>
        /// <returns></returns>
        public static string GetMemberIDByStandID(string StandID)
        {
            string ID = string.Empty;

            string sql = @"select MemberID from tblPartyProbationaryPartyMember where StandID='" + StandID + "' order by MemberID desc limit 1";
            object obj = MySqlHelper.ExecuteScalar(sql);
            if (obj != null)
            {
                ID = obj.ToString();
            }
            return ID;
        }

        /// <summary>
        /// 根据申请ID获取会议通过时间及审批通过时间，2个表，第一为会议通过时间，第二条为审批通过时间
        /// </summary>
        /// <param name="AppllicationID">申请ID</param>
        /// <returns></returns>
        public static DataSet GetTime(string AppllicationID)
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                StringBuilder sbsql = new StringBuilder();
                sbsql.AppendFormat(@"select * from tblpartyJoinMeetingEx where StandID =(
                                select  StandID from tblPartyJoinLinkExample 
                                where AppllicationID='{0}' and CurrentStepID='JoinStep22' order by CreateTime desc limit 1 );


                                select * from tblpartyJoinMeetingEx where StandID =(
                                select StandID from tblPartyJoinLinkExample 
                                where AppllicationID='{0}' and CurrentStepID='JoinStep26' order by CreateTime desc limit 1)", AppllicationID);
                DataSet ds = MySqlHelper.ExecuteDataSet(sbsql.ToString());
                return ds;
            }
        }
        #endregion
    }
}
